/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package LoginManager;

import java.sql.*;
import DBManager.DBConnection;

/**
 *
 * @author Alex
 */
public class LoginManager {
     public boolean Login(String username, String password)
    {
        boolean result = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("SELECT * FROM employee WHERE Username = ? AND Password = ?");

            //append values for the parameters
            int i=1;
             pstmt.setString(i++, username);
              pstmt.setString(i++, password);



            //execute SQL statement
        ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

 while(rs.next())
 {
 result=true;
 }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }

     public boolean addSession(Login newLogin)
    {
        boolean result2 = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
            PreparedStatement pstmt =
                conn.prepareStatement("INSERT "
                    + "INTO login(username,password)"
                    + " values(?,?)");

            //append values for the parameters
            int i=1;
             pstmt.setString(i++, newLogin.getUsername());
              pstmt.setString(i++, newLogin.getPassword());



            //execute SQL statement
            pstmt.executeUpdate();

            result2 = true;
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result2;
    }

      public String Login2()
    {

        String result= "";

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("SELECT * FROM login");

            //append values for the parameters






            //execute SQL statement
        ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

 while(rs.next())
 {
 result=rs.getString(2);
 }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
}
